#!/bin/bash
# This deploy hook gets executed after dependencies are resolved and the
# build hook has been run but before the application has been started back
# up again.  This script gets executed directly, so it could be python, php,
# ruby, etc.

source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate

if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ]
then
    echo "Copying $OPENSHIFT_REPO_DIR/wsgi/openshift/sqlite3.db to $OPENSHIFT_DATA_DIR"
    cp "$OPENSHIFT_REPO_DIR"wsgi/openshift/sqlite3.db $OPENSHIFT_DATA_DIR
    python "$OPENSHIFT_REPO_DIR".openshift/action_hooks/secure_db.py | tee ${OPENSHIFT_DATA_DIR}/CREDENTIALS
else
    echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/openshift/manage.py syncdb --noinput'"
    python "$OPENSHIFT_REPO_DIR"wsgi/openshift/manage.py syncdb --noinput
fi

echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/openshift/manage.py collectstatic --noinput'"
python "$OPENSHIFT_REPO_DIR"wsgi/openshift/manage.py collectstatic --noinput
